<template>
  <div>
    <el-form ref="pram" :model="pram" :rules="rules" label-width="80px" @submit.native.prevent>
      <el-form-item label="状态" prop="status">
        <el-select v-model="pram.status" placeholder="状态" clearable style="width: 100%">
          <el-option label="确定核销" :value="1"/>
          <el-option label="拒绝" :value="2"/>
        </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="exchangeTime">
        <el-date-picker v-model="pram.exchangeTime" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd HH:mm:ss" type="datetime" placement="bottom-end" @change="onchangeTime" placeholder="核销日期"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handlerSubmit('pram')" v-hasPermi="['admin:goods:exchange:check']">确定</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import * as goodsApi from '@/api/goods.js'
import * as systemSetting from '@/api/systemSetting.js'
import {getToken} from "@/utils/auth";
import {Debounce} from '@/utils/validate'
export default {
  // name: "edit"
  components: { },
  props: {
    editData: {
      type: Object,
      default: () => {
        return { rules: [] }
      }
    },
  },
  data() {
    return {
      constants:this.$constants,
      pram: {
        exchangeTime: null,
        status:null,
        id: null,
      },
      rules: {
        status: [{ required: true, message: '请选择状态', trigger: ['blur', 'change'] }],
        exchangeTime: [{ required: true, message: '请选择日期', trigger: ['blur', 'change'] }],
      },
    }
  },
  mounted() {
    this.initEditData()
  },
  methods: {
    close() {
      this.$emit('hideEditDialog')
    },

    initEditData() {
      const { exchangeTime, status, id } = this.editData //通过list中slot-scope=“scope“，scope.$index就是该行的下标，scope.row就是该行的数据所有消息对象，有了这两个参数就可以实现编辑、删除功能（this.editData就是scope.row传入的对象参数）
      this.pram.exchangeTime = exchangeTime
      this.pram.status = status === 0 ? null : status
      this.pram.id = id
    },

    handlerSubmit:Debounce(function(form) {
      this.$refs[form].validate(valid => {
        if (!valid) return
        this.handlerSave()
      })
    }),
    handlerSave() {
      goodsApi.doExchangeCheck(this.pram).then(data => {
        this.$message.success('操作成功')
        this.$emit('hideEditDialog')
      })
    },
  }
}
</script>

<style scoped lang="scss">

</style>
